<template>
	<view class="lhc-textarea">
		<textarea v-model="tema" @blur="teMaChange" auto-height placeholder="请输入需要解析的文本" maxlength="-1" style="border:1rpx solid rgb(192, 196, 204);min-height:340rpx;width: 99%;"/>
		<!-- <u--textarea v-model="tema" @blur="teMaChange()" placeholder="请输入需要解析的文本" border="surround" height="340rpx" style="border:1px solid rgb(192, 196, 204);"></u--textarea> -->
		<view class="lhc-textarea__note">一条数据一行，回车分行。文本可替换的符号：“,” “.” “/” “|” “空格”。</view>
		<view class="lhc-textarea__note">如：“31各10”；“兔龙各号30”；“兔龙各30”； “红波各号30”；</view>
		<u-button class="lhc-textarea__but" type="success" text="开始解析" @click="checkGrid"></u-button>
	</view>
</template>

<script>
	import toPinyin from '@/utils/toPinyin.js'
	import {initFuc,branchAnalysis} from '@/utils/lottery/lhc.js'
	export default {
		name:'lhc-analysis',
		props:{
			ball:{
				type:Array,
				default: () => {
				    return []
				}
				
			},
			zodiac:{
				type:Array,
				default: () => {
				    return []
				}
				
			},
			rulesInfo:{
				type:Object,
				default: () => {
				    return {};
				}
				
			},
			isAddOrder:{
				type:Boolean,
				default: () => {
				    return false;
				}
				
			}
		},
		data() {
			return {
				tema:''
			}
		},
		mounted() {
			
		},
		methods: {
			teMaChange(e){
				this.tema = this.replaceStr(this.tema);
			},
			replaceStr(val){
				let str = null;
				str = val.replace(/\||\.|\/|\，|\-|\+|\。|\*| /g, ',');
				str = str.replace(/候/g,'猴');
				str = str.replace(/兰/g, '蓝');
				return str;
			},
			checkGrid(){
				let arr = this.tema.split("\n");
				arr.map(item=>{
					if(item) {
						if(item.indexOf('各号') === -1 && item.indexOf('各') === -1) {
							uni.$u.toast('文本格式错误！金额前需加上“各”字');
							return false;
						}
						this.getTeMaRuleToNuber(item)
					}
				});
				this.tema = '';
				// if(this.tema)
			},
			getTeMaRuleToNuber(str){
				let arr = [];
				if(str.indexOf('各号') !== -1) {
					arr = str.split('各号');
				}else{
					arr = str.split('各');
				}
				let money = 0;
				if(arr[1].indexOf(',') !== -1){
					let moneyArr = arr[1].split(',');
					if(moneyArr.length > 2) {
						uni.$u.toast('金额格式不正确');
						return false;
					}
					
					money = (moneyArr[0].replace(/[^0-9]/ig,'')) + '.' + (moneyArr[1].replace(/[^0-9]/ig,''));
				}else{
					money = arr[1].replace(/[^0-9]/ig,'');
				}
				
				let nub = [];
				let benxiao = [];
				let isXiao = false;
				if(!(arr[0].replace(/[^0-9]/ig,'') > 0) && arr[0].indexOf(',') !== -1){
					arr[0].split(',').map(item=>{
						nub = nub.concat(branchAnalysis(item,this.ball));
					});
				}else if((new RegExp(this.zodiac[0])).test(arr[0])){
					nub = branchAnalysis(arr[0].replace(this.zodiac[0],''),this.ball);
					benxiao= branchAnalysis(this.zodiac[0],this.ball);
					
				}else if(((new RegExp('家禽|野兽|吉美|凶丑|阴性|阳性|单笔|双笔|天肖|地肖|白边|黑中|女肖|男肖|琴|棋|书|画|五福肖|红肖|蓝肖|绿肖')).test(str))){
					var result = branchAnalysis(arr[0],this.ball);
					result.map(item=>{
						if(item.title === this.zodiac[0]){
							benxiao.push(item);
						}else{
							nub.push(item);
						}
					})
				}else{
					nub = branchAnalysis(arr[0],this.ball);
				}
				
				if(str.indexOf('各号') !== -1) {
					if(benxiao.length) {
						nub = nub.concat(benxiao);
					}
				}else{
					if(benxiao.length) {
						let betting_code = benxiao;
						let betting_money = money;
						if(str.indexOf('各') !== -1) {
							betting_money = (parseFloat(money) / parseInt(betting_code.length)).toFixed(2);
						}
						
						let betting_total_money = (parseFloat(betting_money) * parseInt(betting_code)).toFixed(2);
						let  obj = {
							betting_code:betting_code,
							alias:this.rulesInfo.alias,
							betting_rate:this.rulesInfo.rate,
							betting_max_rate:this.rulesInfo.max_rate,
							pid:this.rulesInfo.pid,
							typeid:this.rulesInfo.typeid,
							title:this.rulesInfo.title,
							pid_name:this.rulesInfo.pid_name,
							multiple:1,
							amount:betting_code.length,
							money:betting_money,
							total_money:betting_total_money,
							remark:str,
						}
						
						this.$emit('click',true,obj);
					}
				}
				
				
				if(nub.length) {
					let betting_code = nub;
					let betting_money = 0;
					if(str.indexOf('各号') !== -1) {
						betting_money = money;
					}else{
						if(((new RegExp('鼠|兔|牛|虎|龙|蛇|马|羊|猴|鸡|狗|猪')).test(arr[0])) || (new RegExp('家禽|野兽|吉美|凶丑|阴性|阳性|单笔|双笔|天肖|地肖|白边|黑中|女肖|男肖|琴|棋|书|画|五福肖|红肖|蓝肖|绿肖')).test(arr[0])) {
							betting_money = (parseFloat(money) / 4).toFixed(2);
						}else{
							betting_money = money;
						}
						
					}
					let betting_total_money = (parseFloat(betting_money) * parseInt(betting_code.length)).toFixed(2);
					let  obj = {
						betting_code:betting_code,
						alias:this.rulesInfo.alias,
						betting_rate:this.rulesInfo.rate,
						betting_max_rate:this.rulesInfo.max_rate,
						pid:this.rulesInfo.pid,
						typeid:this.rulesInfo.typeid,
						title:this.rulesInfo.title,
						pid_name:this.rulesInfo.pid_name,
						multiple:1,
						amount:betting_code.length,
						money:betting_money,
						total_money:betting_total_money,
						remark:str,
					}

					console.log(obj)
					
					this.$emit('click',true,obj);
				}
			},
		}
	}
</script>

<style lang="less">
.lhc-textarea{
	margin-top: 20rpx;
	&__note{
		font-size: 24rpx;
		font-weight: 500;
		color:#dd6161;
		margin-top:20rpx;
	}
	&__but{
		margin-top:30rpx;
	}
}
</style>
